package com.cxs.musicplaywidget.data;

import com.cxs.musicplaywidget.player.data.MusicInfo;
import com.cxs.musicplaywidget.service.idl.MyAgentProxy;

import java.util.List;
import java.util.Objects;

/**
 * @ClassName Device
 * @Author cxs
 * @Version 1.0
 * @Description TODO
 * @Date 2022/03/07
 */
public class MDevice implements Cloneable, Comparable<MDevice>{

    /**
     * 设备索引
     */
    private byte index = 0;

    /**
     * 设备Id
     */
    private String deviceId = "";

    /**
     * 设备名称
     */
    private String name = "";

    /**
     * 设备类型。phone,table
     */
    private String type = "";

    /**
     * 设备在卡片中的样式
     */
    private String cls = "";

    /**
     * 播放列表
     */
    private List<MusicInfo> playList = null;

    /**
     * 代理对象
     */
    private MyAgentProxy proxy = null;

    public MDevice() {
    }

    public MDevice(MyAgentProxy proxy) {
        this.proxy = proxy;
    }

    public byte getIndex() {
        return index;
    }

    public void setIndex(byte index) {
        this.index = index;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getCls() {
        return cls;
    }

    public void setCls(String cls) {
        this.cls = cls;
    }

    public List<MusicInfo> getPlayList() {
        return playList;
    }

    public void setPlayList(List<MusicInfo> playList) {
        this.playList = playList;
    }

    public void setProxy(MyAgentProxy proxy) {
        this.proxy = proxy;
    }

    /**
     * 获取代理对象，不能用get方式获取，否则toZSONObject会异常
     * @return
     */
    public MyAgentProxy proxy() {
        return proxy;
    }

    public MDevice dup() {
        try {
            return (MDevice)this.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MDevice that = (MDevice) o;
        return Objects.equals(deviceId, that.deviceId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(deviceId);
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return "MDevice{" +
                "index=" + index +
                ", deviceId='" + deviceId + '\'' +
                ", name='" + name + '\'' +
                ", type='" + type + '\'' +
                ", cls='" + cls + '\'' +
                ", proxy=" + proxy +
                '}';
    }

    @Override
    public int compareTo(MDevice device) {
        return this.index - device.index;
    }
}
